﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JKF.DataModule.IDAL;
using JKF.DataModule.DALFactory;
using System.Data;
using JKF.Substructure;

namespace JKF.BusinessLayer.BLL
{
    /// <summary>
    /// 自定义的一个公共的方法类，用于获取当前访问页面的操作权限
    /// </summary>
    public partial class bllPermission
    {
        private readonly IdalPermission dal = DataAccess_Other.CreatedalPermission();

        /// <summary>
        /// 根据当前用户ID，及访问的模块名称英文来获取相应的操作权限
        /// </summary>
        /// <param name="module_name_en">模块名称</param>
        /// <param name="user_key">用户ID</param>
        /// <param name="preview">预览权限</param>
        /// <param name="add">添加权限</param>
        /// <param name="edit">修改权限</param>
        /// <param name="delete">删除权限</param>
 
        public void GetUserPermission(string module_name_en, Guid user_key, ref bool preview, ref bool add, ref bool edit, ref bool delete)
        {
            dal.GetUserPermission(module_name_en, user_key,ref preview,ref add,ref edit,ref delete); 
        }

        /// <summary>
        /// 获取操作权限数据
        /// </summary>
        /// <returns></returns>
        public DataTable GetUserRolePermission()
        {
            const string cacheName = "UserRolePermission";
            if (!CacheManage.HadCache(cacheName))
            {
                // 获取当前用户所在区域，总店的获取所有
                // 判断当前用户的角色去加载对应的角色下拉列表
                DataTable dt =  dal.GetUserRolePermission();
                
                if (dt.Rows.Count>0)
                {
                    return dt;
                }
                else
                {
                    return null;
                }
            }
            return (DataTable)CacheManage.GetCache(cacheName);
        }
    }
}
